home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3689 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: realloc question
  5. Date: Tue, 30 Jan 96 14:58:00 GMT
  6. Organization: none
  7. Message-ID: <823013880snz@genesis.demon.co.uk>
  8. References: <4ehi4b$qfo@news.texas.net> <QG28B81O@gellbo.gellrich-gmbh.de>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <QG28B81O@gellbo.gellrich-gmbh.de>
  15.            wolfi@gellbo.gellrich-gmbh.de "Actio wolfi" writes:
  16.  
  17. >                        if(NULL == (ptr = no_elements ?                        
  18. >            \
  19. >                                (typ *)realloc((char *)ptr,                    
  20. >                \
  21. >                                                (unsigned)(no_allocated +=
  22. > increment) * sizeof(typ)) : \
  23.  
  24. In many cases a geometric increase makes more sense e.g.
  25.  
  26.    no_allocated *= 2
  27.  
  28. or if you find that excessive perhaps:
  29.  
  30.    no_allocated += no_allocated/2
  31.  
  32. >                                (typ *)malloc(sizeof(typ) * (no_allocated =
  33. > increment))))      \
  34.  
  35. Of course no_callocated must be initialised to a nonzero value
  36.  
  37.    no_allocated = INITIAL_VALUE
  38.  
  39. -- 
  40. -----------------------------------------
  41. Lawrence Kirby | fred@genesis.demon.co.uk
  42. Wilts, England | 70734.126@compuserve.com
  43. -----------------------------------------
  44.